package com.xxx.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xxx.entity.Product;

@Controller
@RequestMapping("product")
public class ProductController {
	/*
	 * 通过 GET 请求获取表单页面，而通过 POST 请求提交表单页面，
	 * 因此获取表单页面和提交表单 页面的 URL 是相同的。
	 */
	@RequestMapping(value="add",method=RequestMethod.GET)
	public String toAdd(Model model){
		Product p=new Product();
		p.setBrand("2");
		p.setSellType("self");
		List<String> color=new ArrayList<String>();
		color.add("蓝色");
		color.add("绿色");
		color.add("红色");
		
		model.addAttribute("command",p);//默认值是command
		model.addAttribute("product",p);
		return "/product.jsp";
	}
	
	@RequestMapping(value="add",method=RequestMethod.POST)
	public String add(Product product,Model model){
		System.out.println(product);
		for(String temp:product.getColor())
			System.out.println(temp);
		System.out.println(product.getSellType());
		System.out.println(product.getBrand());
		//System.out.println(product.getProducingArea());
		return "/showproduct.jsp";
	}

}
